package com.ruoyi.web.controller.weather;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

@RestController
public class WeatherController {

    @GetMapping("/getWeatherByLocalIP")
    public AjaxResult getWeather() throws UnsupportedEncodingException {
        AjaxResult result = AjaxResult.success();
//        String localCityName = GetLocationAndIP.getLocalCityName();
        String localCityName = "珠海市";
        //调用天气API
        String encodeCity = URLEncoder.encode(localCityName, "UTF-8");
        System.out.println(encodeCity);
//        String url = "http://apis.juhe.cn/simpleWeather/query?city=" + encodeCity + "&key=81fe33a6077267b2e4ae2967af47eeb7";
//        String weatherInfo = HttpUtils.sendGet(url);
//        result.put("msg", weatherInfo);
        result.put("msg", jsonStr);
        return result;
    }

    final String jsonStr = "{\n" +
            "\t\"reason\":\"查询成功!\",\n" +
            "\t\"result\":{\n" +
            "\t\t\"city\":\"珠海\",\n" +
            "\t\t\"realtime\":{\n" +
            "\t\t\t\"temperature\":\"18\",\n" +
            "\t\t\t\"humidity\":\"60\",\n" +
            "\t\t\t\"info\":\"多云\",\n" +
            "\t\t\t\"wid\":\"01\",\n" +
            "\t\t\t\"direct\":\"西北风\",\n" +
            "\t\t\t\"power\":\"1级\",\n" +
            "\t\t\t\"aqi\":\"52\"\n" +
            "\t\t},\n" +
            "\t\t\"future\":[\n" +
            "\t\t\t{\n" +
            "\t\t\t\t\"date\":\"2024-01-21\",\n" +
            "\t\t\t\t\"temperature\":\"12\\/21℃\",\n" +
            "\t\t\t\t\"weather\":\"多云转小雨\",\n" +
            "\t\t\t\t\"wid\":{\n" +
            "\t\t\t\t\t\"day\":\"01\",\n" +
            "\t\t\t\t\t\"night\":\"07\"\n" +
            "\t\t\t\t},\n" +
            "\t\t\t\t\"direct\":\"北风转东北风\"\n" +
            "\t\t\t},\n" +
            "\t\t\t{\n" +
            "\t\t\t\t\"date\":\"2024-01-22\",\n" +
            "\t\t\t\t\"temperature\":\"7\\/14℃\",\n" +
            "\t\t\t\t\"weather\":\"小雨\",\n" +
            "\t\t\t\t\"wid\":{\n" +
            "\t\t\t\t\t\"day\":\"07\",\n" +
            "\t\t\t\t\t\"night\":\"07\"\n" +
            "\t\t\t\t},\n" +
            "\t\t\t\t\"direct\":\"北风\"\n" +
            "\t\t\t},\n" +
            "\t\t\t{\n" +
            "\t\t\t\t\"date\":\"2024-01-23\",\n" +
            "\t\t\t\t\"temperature\":\"7\\/9℃\",\n" +
            "\t\t\t\t\"weather\":\"小雨转多云\",\n" +
            "\t\t\t\t\"wid\":{\n" +
            "\t\t\t\t\t\"day\":\"07\",\n" +
            "\t\t\t\t\t\"night\":\"01\"\n" +
            "\t\t\t\t},\n" +
            "\t\t\t\t\"direct\":\"北风\"\n" +
            "\t\t\t},\n" +
            "\t\t\t{\n" +
            "\t\t\t\t\"date\":\"2024-01-24\",\n" +
            "\t\t\t\t\"temperature\":\"7\\/10℃\",\n" +
            "\t\t\t\t\"weather\":\"多云\",\n" +
            "\t\t\t\t\"wid\":{\n" +
            "\t\t\t\t\t\"day\":\"01\",\n" +
            "\t\t\t\t\t\"night\":\"01\"\n" +
            "\t\t\t\t},\n" +
            "\t\t\t\t\"direct\":\"东北风转持续无风向\"\n" +
            "\t\t\t},\n" +
            "\t\t\t{\n" +
            "\t\t\t\t\"date\":\"2024-01-25\",\n" +
            "\t\t\t\t\"temperature\":\"9\\/16℃\",\n" +
            "\t\t\t\t\"weather\":\"多云\",\n" +
            "\t\t\t\t\"wid\":{\n" +
            "\t\t\t\t\t\"day\":\"01\",\n" +
            "\t\t\t\t\t\"night\":\"01\"\n" +
            "\t\t\t\t},\n" +
            "\t\t\t\t\"direct\":\"持续无风向转东北风\"\n" +
            "\t\t\t}\n" +
            "\t\t]\n" +
            "\t},\n" +
            "\t\"error_code\":0\n" +
            "}";

}
